﻿@using OASystem.Model;
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户添加</title>
    <link href="~/css/tail.css" rel="stylesheet" type="text/css" />
    <link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="~/js/jquery.js"></script>
    <script>
        function change() {
            var height01 = $(window).height();
            $(".top").css('height', height01 - 35 + "px");
        }
    </script>
</head>

<body style="border-radius: 8px" onload="change()">
    <!--<div class="title"><h2>通知详情</h2></div>-->
    <div id="form_demo">
        <div class="top">
            <div>
                <div class="top_out">
                    <table class="table">
                        <tbody>

                            <tr>
                                <td style="border-top: none">用户名：<i class="i_start"></i></td>
                                <td colspan="6" style="text-align: left;border-top: none"><input type="text" id="UserName" name="name" minlength="2" required id="recodeTit"></td>
                            </tr>
                            <tr>
                                <td>姓名：</td>
                                <td style="text-align: left">
                                    <input class="long_text" id="EmployeeName" />
                                <td>密码：</td>
                                <td colspan="3" style="text-align: left"><input type="password" class="long_text" id="UserPwd"></td>
                            </tr>
                            <tr>
                                <td>所属部门：</td>
                                <td style="text-align: left">
                                    <select id="DepartId">
                                        @if (ViewBag.List != null)
                                        {
                                            foreach (Departinfo item in ViewBag.List)
                                            {
                                                <option value="@item.DepartId">@item.DepartName</option>
                                            }
                                        }
                                    </select>
                                </td>
                                <td>所属职位：</td>
                                <td style="text-align: left">
                                    <select id="PosId">
                                        @if (ViewBag.Position != null)
                                        {
                                            foreach (Position item in ViewBag.Position)
                                            {
                                                <option value="@item.PosId">@item.PosName</option>
                                            }
                                        }

                                    </select>
                                </td>
                                <td>所各状态：</td>
                                <td colspan="3" style="text-align: left">
                                    <select id="Status">
                                        <option value="1">启动</option>
                                        <option value="0">关闭</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td style="line-height: 240px">备注：</td>
                                <td colspan="8" style="text-align: left"><input id="Remark" style="width: 100%;height: 240px" /></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="bot_btn">
                <input class="btn" id="btn" type="button" value="保存" />
                <button class="btn btn1">返回</button>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="~/js/jquery.js"></script>
<script src="~/js/date/js/laydate.js"></script>
<script src="~/js/layer.js"></script>
<script>
    ///用户管理添加方法(判断数据是否重复)
    $(function () {
        $("#btn").click(function () {
            var pos = $("#PosId").val();
            var data = {};
            data.UserName = $("#UserName").val();
            data.EmployeeName = $("#EmployeeName").val();
            data.Password = $("#UserPwd").val();
            data.DepartId = $("#DepartId").val();
            data.Status = $("#Status").val();
            data.Remark = $("#Remark").val();
            var name = data.UserName;
            $.ajax({
                type: "post",
                url: "/Person_tail/QueryPerson?name=" + name,
                success: function (result) {
                    if (result.success) {
                        layer.msg('用户名重复!', { icon: 6, time: 1000 });
                    } else {
                        $.ajax({
                            type: "post",
                            data: data,
                            url: "/Person_tail/MoreAdd?pos=" + pos,
                            success: function (responseResult) {
                                if (responseResult.success) {
                                    layer.msg('添加成功!', { icon: 6, time: 1000 });
                                    window.location.href = "/Home/Person";
                                } else {
                                    layer.msg('添加失败!', { icon: 6, time: 1000 });
                                }
                            }
                        })
                    }
                }
            })

        })
    })





    //时间格式化函数
    function getFormatTime(time) {
        var time = new Date(parseInt(time));
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
    }
    function add0(m) { return m < 10 ? '0' + m : m }
</script>

</html>
